//By Robin_TYUT 2010/08/19
//Thank U 4 sharing!
jQuery.fn.extend(
{
    OpenDiv: function()
    {

    	
    	
    	if(document.getElementById("BigDiv")){
    		return;
    	}
    	
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth + "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "10000";
        document.body.appendChild(maskObj);
        //$("#BigDiv").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
        $("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");
        $("body").attr("style", "overflow-y:hidden");
        window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        this.css("position", "absolute");
        this.css("z-index", "10001");
        this.css("background", "#fff");
        this.css("left", Div_leftposition + "px");
        this.css("top", Div_topposition + "px");
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    }
    , 
    OpenDiv2: function()
    {

        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv2');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth + "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "20000";
        $("body").attr("scroll", "no");
        document.body.appendChild(maskObj);
        //$("#BigDiv2").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("#BigDiv2").attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#BigDiv2").attr("divbox_scrollleft", $.ScrollPosition().Left);
        $("#BigDiv2").attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");
        window.scrollTo($("#BigDiv2").attr("divbox_scrollleft"), $("#BigDiv2").attr("divbox_scrolltop"));
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        this.css("position", "absolute");
        this.css("z-index", "20001");
        this.css("background", "#fff");
        this.css("left", Div_leftposition + "px");
        this.css("top", Div_topposition + "px");
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    },
    OpenDiv3: function()
    {

    	var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv3');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth+ "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "20000";
        $("body").attr("scroll", "yes");
        document.body.appendChild(maskObj);
        //$("#BigDiv2").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("html").css("overflow","auto");
        $("body").css("overflow","auto");
        $("#BigDiv3").attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#BigDiv3").attr("divbox_scrollleft", $.ScrollPosition().Left);
        window.scrollTo($("#BigDiv3").attr("divbox_scrollleft"), $("#BigDiv3").attr("divbox_scrolltop"));
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        this.css("position", "absolute");
        this.css("z-index", "20001");
        this.css("background", "#fff");
        this.css("left", Div_leftposition>0?Div_leftposition:0+ "px");
        this.css("top", Div_topposition>0?Div_topposition:0+ "px");
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    },
    OpenDiv4: function(ele, zIndex) {
    	if (!ele) {
    		ele = 'BigDiv4'
    	}
        if(document.getElementById(ele)){
            return;
        }
        if (!zIndex) {
        	zIndex='20000'
        }
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', ele);
        maskObj.style.position = "fixed";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth+ "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = zIndex;
        /*$("body").attr("scroll", "no");*/
        document.body.appendChild(maskObj);
        $("#" + ele).data("divbox_selectlist", $("select:visible"));
        $("select:visible").hide();
        $("#" + ele).attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#" + ele).attr("divbox_scrollleft", $.ScrollPosition().Left);
        $("#" + ele).attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");
        // 因为 body 的样式 overflow-y:scroll 所以应该改变  body 的 scroll
        if ($("body").css("overflow")) {
            // document.body.scrollTo($("#" + ele).attr("divbox_scrollleft"), $("#" + ele).attr("divbox_scrolltop"));      
        	var body
            if (document.documentElement) {
            	body = document.documentElement
            } else {
            	body = document.body
            }
            // $(window).scrollTop($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"))
            $(body).scrollLeft($("#" + ele).attr("divbox_scrollleft")) 
            $(body).scrollTop($("#" + ele).attr("divbox_scrolltop"))
        } else {
        	$(window).scrollLeft($("#" + ele).attr("divbox_scrollleft"))
        	$(window).scrollTop($("#" + ele).attr("divbox_scrolltop"));
        }
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var Div_topposition = (MyDiv_h / 2);
        var Div_leftposition = (MyDiv_w / 2);
        
        this.css("position", "fixed");
        this.css("z-index", zIndex - 0 + 1);
        this.css("background", "#fff");
        this.css("left", '50%');
        this.css("top", '50%');
        this.css("margin-left", -Div_leftposition + 'px');
        this.css("margin-top", -Div_topposition + 'px');
        
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    }, 
    CloseDiv4: function(ele)
    {
    	if (!ele) {
    		ele = 'BigDiv4'
    	}
        if ($.browser.mozilla)
        {
            this.hide();

        } else
        {
            this.fadeOut("fast");

        } 
        
        $("html").css("overflow", $("#" + ele).attr("htmloverflow"));
        // 因为 body 的样式 overflow-y:scroll 所以应该改变  body 的 scroll
        if ($("body").css("overflow")) {
            // document.body.scrollTo($("#" + ele).attr("divbox_scrollleft"), $("#" + ele).attr("divbox_scrolltop"));      
        	var body
            if (document.documentElement) {
            	body = document.documentElement
            } else {
            	body = document.body
            }
            // $(window).scrollTop($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"))
            $(body).scrollLeft($("#" + ele).attr("divbox_scrollleft")) 
            $(body).scrollTop($("#" + ele).attr("divbox_scrolltop"))
        } else {
        	$(window).scrollLeft($("#" + ele).attr("divbox_scrollleft"))
        	$(window).scrollTop($("#" + ele).attr("divbox_scrolltop"));
        }
        // document.body.scrollTo($("#" + ele).attr("divbox_scrollleft"), $("#" + ele).attr("divbox_scrolltop"));
        if ($("#" + ele).data("divbox_selectlist")) {
        	$("#" + ele).data("divbox_selectlist").show();
        }
        $("#" + ele).remove();
        $("#newLoading").remove();
    },
    CloseDiv3: function()
    {

        if ($.browser.mozilla)
        {
            this.hide();

        } else
        {
            this.fadeOut("fast");

        } 
        $("body").css("overflow", "visible");
        $("html").css("overflow", "visible");
        window.scrollTo($("#BigDiv3").attr("divbox_scrollleft"), $("#BigDiv3").attr("divbox_scrolltop"));
        //$("#BigDiv2").data("divbox_selectlist").show();
        $("#BigDiv3").remove();

    },
    CloseDiv2: function()
    {

        if ($.browser.mozilla)
        {
            this.hide();

        } else
        {
            this.fadeOut("fast");

        } 
        $("html").css("overflow", $("#BigDiv2").attr("htmloverflow"));
        window.scrollTo($("#BigDiv2").attr("divbox_scrollleft"), $("#BigDiv2").attr("divbox_scrolltop"));
        //$("#BigDiv2").data("divbox_selectlist").show();
        $("#BigDiv2").remove();

    },
    CloseDiv: function()
    {

        if ($.browser.mozilla)
        {
            this.hide();

        } else
        {
            this.fadeOut("fast");

        } 
        
        $("body").attr("style", "overflow-y:auto");
        window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
        //$("#BigDiv").data("divbox_selectlist").show();
        $("#BigDiv").remove();
        $("#newLoading").remove();
        
        

    },
    OpenDiv5: function()
    {
    	if(document.getElementById("BigDiv")){
    		return;
    	}
    	
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth + "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "10000";
        document.body.appendChild(maskObj);
        //$("#BigDiv").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
        $("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");
        $("body").attr("style", "overflow-y:hidden");
        window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        this.css("position", "absolute");
        this.css("z-index", "10001");
        this.css("background", "#fff");
        this.css("left", "5%");
        this.css("top", "30%");
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    },
    OpenDiv6: function()
    {
    	if(document.getElementById("BigDiv")){
    		return;
    	}
    	
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#111";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth + "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "10000";
        document.body.appendChild(maskObj);
        //$("#BigDiv").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
        $("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
        $("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");
        $("body").attr("style", "overflow-y:hidden");
        window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        this.css("position", "absolute");
        this.css("z-index", "10001");
        this.css("background", "#fff");
        this.css("left", "6%");
        this.css("top", "50%");
        if ($.browser.mozilla)
        {
            this.show();
            return;
        }
        this.fadeIn("fast");

    }
});
$.extend(
{
    PageSize:function ()
    {
        var width=0;
        var height=0;
        width=window.innerWidth!=null?window.innerWidth:document.documentElement&&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body!=null?document.body.clientWidth:null;
        height=window.innerHeight!=null?window.innerHeight:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body!=null?document.body.clientHeight:null;
        return {Width:width,Height:height};
    }
    ,ScrollPosition:function ()
    {
        var top=0,left=0;
        if($.browser.mozilla)
        {
            top=window.pageYOffset;
            left=window.pageXOffset;
            
        }
        else if($.browser.msie)
        {
            top=document.documentElement.scrollTop;
            left=document.documentElement.scrollLeft;

        }
        else if(document.body)
        {
            top=document.body.scrollTop;
            left=document.body.scrollLeft;
        }
        return {Top:top,Left:left};
        
    }
});

